<template>
  <div class="mainContent">
    <div class="shiftText">
      <el-icon size="60" color="#231815">
        <Back />
      </el-icon>
      <div class="stxt">文字输入</div>
    </div>

    <button id="btnStart" class="voiceBtn">开始</button>
    <button id="btnStop" class="voiceBtn">停止</button>
    <textarea
      rows="10"
      id="varArea"
      readonly="true"
      style="width: 100%; height: 100%"
    ></textarea>
    <!-- <div style="margin-top: 30px; font-size: 30px">
      语音识别的文字为：{{ resText || "--" }}
    </div> -->
    <div class="canvas-container">
      <canvas ref="waveformCanvas" width="500" height="200"></canvas>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onBeforeUnmount } from "vue";

const resText = ref(""); // 语音识别的文字

const waveformCanvas = ref(null); // Canvas 元素引用

onMounted(() => {
  // 动态导入库
  Promise.all([
    import("@/assets/js/wav.js"),
    import("@/assets/js/pcm.js"),
    import("@/assets/js/recorder-core.js"),
    import("@/assets/js/main.js"),
    import("@/assets/js/wsconnecter.js"),
  ])
    .then(() => {})
    .catch((err) => {
      console.error("Failed to load libraries:");
    });
});

// 组件卸载时清理资源
onBeforeUnmount(() => {});
</script>

<style lang="scss" scoped>
.mainContent {
  background: #dedede;
  width: 100%;
  height: 30vh;
  position: fixed;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;

  .shiftText {
    display: flex;
    align-items: center;
    margin: 25px;

    .stxt {
      width: 108px;
      height: 50px;
      color: #0960ec;
      font-size: 36px;
      margin-left: 15px;
      padding-top: 5px;
    }
  }

  .voiceBtn {
    width: 200px;
    height: 80px;
    border-radius: 36px;
    overflow: hidden;
    background-color: #ccc;
    font-size: 36px;
    margin: 0 10px;
    outline: none;
    border: none;

    &:active {
      background-color: #aaa;
    }
  }
  .voiceBtn:focus {
    outline: none; /* 移除聚焦边框 */
  }
  .canvas-container {
    margin-top: 20px;
    background-color: white;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  }
}
</style>
